<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-7-28
 * Time: 上午11:06
 */
include('/var/www/html/new/d/module/api/function.class.php');
$txt=json_encode($_REQUEST);
logfile(date('Y-m-d H:i:s').'_zs_return'.$txt,'zs_return.txt');
$json     = json_decode($txt,true);
$res_xml  = $json['xml'];

$response_xml = simplexml_load_string($res_xml);

//$backCount = $response->backCount;
//$orderId = $response->orderId;//祖山订单号
$type =(string)$response_xml->type;
$useCount = (string)$response_xml->useCount;
//logfile('$type'.$type,'zushan_log.txt');
if($type=='use_info'){
    $outOrderId= (string)$response_xml->outOrderId;//票付通订单号
    if (!class_exists("go_sql")) {
        include("/var/www/html/new/conf/le.je");
        $le = new go_sql();
        $le->connect();
    }
    $ac = '16ucom';
    $pw = 'c33367701511b4f6020ec61ded352059';
    $inSide = new SoapClient(null, array("location" => "http://localhost/open/openService/pft_insideMX.php", "uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
    $pft_order_list = $inSide->Order_Globle_Search(
        0,0,0,0,"",
        "","","","","",
        "","",$outOrderId,"",0,
        "","","",1,0,
        0,1,"","","",
        "","","","","",
        "","","1","",""
    );

    if(strlen($pft_order_list)>50){
        $pft_order_xml=simplexml_load_string($pft_order_list);
        $UUsalerid  = (string)$pft_order_xml->Rec->UUsalerid;
        $UUlid  = (string)$pft_order_xml->Rec->UUlid;
        $UUcode  = (string)$pft_order_xml->Rec->UUcode;
        $UUtnum =(int)$pft_order_xml->Rec->UUtnum;
        $actiontime = date('Y-m-d H:i:s');

        $PFT_infunction = new AllFunction();
        $r = $PFT_infunction->Compatible_Check_IN($UUsalerid,$UUcode,$actiontime);

        if($r==100){


            $repMsg = 'success';
            echo  $repMsg;
        }else{
            logfile(date('Y-m-d H:i:s').'$r_'.$r,'zs_return.txt');

            echo  $r;

        }



    }
}elseif($type == 'back_order'){

    $pftorder   = (string)$response_xml->outBackId;//票付通订单号
    $backStatus = (string)$response_xml->backStatus;//是否通过退票申请
    logfile('$backStatus'.$backStatus,'zs_return.txt');
    if($backStatus==1){
        $str = "update uu_order_fx_details set memo='zs_refund_success' where orderid=".$pftorder." limit 1";
        $GLOBALS['le']->query($str);
        $repMsg = 'success';
        logfile('succsess','zs_return.txt');
        echo  $repMsg;
    }else{
        logfile(date('Y-m-d H:i:s').'$backStatus'.$backStatus,'zs_return.txt');
        echo  "$backStatus";
    }

}
function Err_Word($r)
{
    $errCode = array(
        '105' => '找不到订单',
        '121' => '订单状态出错,订单已验证',
        '119' => '订单状态出错,已取消或其他状态',
        '521' => '验证间隔时间未到',
        '133' => '游玩时间未到',
        '134' => '游玩时间已过',
        '118' => '终端服务器无响应',
        '1070' => '订单未支付',
    );
    $eword = $errCode[$r];
    if (!$eword) $eword = '其他错误';
    return $eword;
}
function logfile($txt, $path)
{
    $fp = fopen($path, "a");
    flock($fp, LOCK_EX);
    fwrite($fp, $txt . "\n");
    flock($fp, LOCK_UN);
    fclose($fp);
}